package com.x.bff.app.controller;

import com.x.bff.app.factory.customer.CustomerFactory;
import com.x.bff.app.factory.social.SocialFactory;
import com.x.bff.app.model.vo.social.CustomerResumeFeedbackReqVO;
import com.x.bff.app.model.vo.social.CustomerResumeSearchReqVO;
import com.x.bff.app.model.vo.social.CustomerSlideListVO;
import com.x.bff.app.service.social.SocialService;
import com.x.core.web.api.R;
import com.x.core.web.controller.BaseFrontendController;
import com.x.core.web.page.PageList;
import com.x.redis.domain.LongTypeTuple;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "社交服务")
@Slf4j
@RestController
@RequestMapping("/app/social")
public class SocialController extends BaseFrontendController {

    private final SocialService socialService;
    private final CustomerFactory customerFactory;
    private final SocialFactory socialFactory;

    public SocialController(SocialService socialService,
                            CustomerFactory customerFactory,
                            SocialFactory socialFactory
                            ){
        this.socialService = socialService;
        this.customerFactory = customerFactory;
        this.socialFactory = socialFactory;
    }

    @ApiOperation(value = "划一划列表用户信息查询")
    @GetMapping("/customer/slider/list")
    public R<PageList<CustomerSlideListVO>> slideList(@ApiParam("性别 1 男 2 女") @RequestParam(required = false) Integer gender,
                                          @RequestParam(required = false, defaultValue = "0") Long cursor,
                                          @RequestParam Integer pageSize){
        CustomerResumeSearchReqVO reqVO = new CustomerResumeSearchReqVO();
        reqVO.setCustomerId(getCurrentCustomerId());
        reqVO.setPageDomain(getPageDomain());
        reqVO.setGender(gender);

        PageList<LongTypeTuple> customerIdList = socialService.sliderList(reqVO);
        if (customerIdList.isEmptyList()){
            return R.ok(new PageList<>());
        }
        List<CustomerSlideListVO> resultList = socialFactory.prepare(customerIdList.getList(), getCurrentCustomerIdAndNotCheckLogin());
        return R.ok(customerIdList.map(resultList));
    }

    @ApiOperation(value = "划一划资料读取反馈,返回还可以读取多少用户资料 错误： 10009 表示用户资源已用完，不能在读取资料了")
    @PostMapping("/customer/slide/item/feedback")
    public R<Void> resumeReadFeedback(@RequestBody @Validated CustomerResumeFeedbackReqVO reqVO){
        reqVO.setSessionCustomerId(getCurrentCustomerId());
        socialService.readResume(reqVO);
        return R.ok();
    }
}
